package com.wei.czz.common.dto.store;

import com.wei.czz.common.enums.CommonEnum;
import com.wei.czz.common.tool.BaseEntity;
import com.wei.czz.framework.store.entity.StoreEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-12-01 14:23:40
 * className: StoreDto
 * version: 1.0
 * description:
 */
@Getter
@Setter
@Accessors(chain = true)
public class StoreDto extends BaseEntity {

    /**
     * 主键
     */
    private String id;

    /**
     * 业务主键
     */
    private String businessId;

    /**
     * 名称
     */
    private String name;

    /**
     * 省份
     */
    private Integer addressProvince;

    /**
     * 城市
     */
    private Integer addressCity;

    /**
     * 区县
     */
    private Integer addressDistrict;

    /**
     * 街道
     */
    private Integer addressStreet;

    /**
     * 详细门牌号
     */
    private String address;

    /**
     * 面积（小数点后两位）
     */
    private String area;

    /**
     * 经营大类
     */
    private Integer mainClass;

    /**
     * 经营小类
     */
    private Integer subClass;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 商店基础数据封装
     * @param store 商店对象
     * @return 封装结果
     */
    public static StoreDto map(StoreEntity store) {
        StoreDto storeDto = new StoreDto();
        storeDto.setId(store.getId().toString())
                .setBusinessId(store.getBusinessId().toString())
                .setName(store.getName())
                .setAddressProvince(CommonEnum.filterDefault(store.getAddressProvince()))
                .setAddressCity(CommonEnum.filterDefault(store.getAddressCity()))
                .setAddressDistrict(CommonEnum.filterDefault(store.getAddressDistrict()))
                .setAddressStreet(CommonEnum.filterDefault(store.getAddressStreet()))
                .setAddress(store.getAddress())
                .setArea(CommonEnum.filterDefault(store.getArea(), area -> String.valueOf((double) area / 100)))
                .setMainClass(CommonEnum.filterDefault(store.getMainClass()))
                .setSubClass(CommonEnum.filterDefault(store.getSubClass()))
                .setCreateTime(store.getCreateTime());
        return storeDto;
    }
}
